<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>分类管理 - 便签系统</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.8.1/font/bootstrap-icons.css" rel="stylesheet">
    <link href="/css/custom.css" rel="stylesheet">
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container">
            <a class="navbar-brand" href="/memo/list">
                <i class="bi bi-sticky me-2"></i>便签系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="/memo/list">
                            <i class="bi bi-collection me-1"></i>我的便签
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/memo/add">
                            <i class="bi bi-plus-circle me-1"></i>添加便签
                        </a>
                    </li>
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle active" href="#" id="categoriesDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="bi bi-tag me-1"></i>分类管理
                        </a>
                        <ul class="dropdown-menu" aria-labelledby="categoriesDropdown">
                            <li><a class="dropdown-item active" href="/category/list"><i class="bi bi-list-ul me-1"></i>查看分类</a></li>
                            <li><a class="dropdown-item" href="/category/add"><i class="bi bi-plus-lg me-1"></i>添加分类</a></li>
                        </ul>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="/memo/recycle-bin">
                            <i class="bi bi-trash me-1"></i>回收站
                        </a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item">
                        <a class="nav-link" href="/logout">
                            <i class="bi bi-box-arrow-right me-1"></i>退出登录
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <div class="container mt-4">
        <div class="row mb-4">
            <div class="col">
                <h2 class="mb-0">
                    <i class="bi bi-tag me-2"></i>分类管理
                </h2>
                <p class="text-muted">管理您的便签分类</p>
            </div>
            <div class="col-auto align-self-center">
                <a href="/category/add" class="btn btn-primary">
                    <i class="bi bi-plus-lg me-1"></i>添加分类
                </a>
            </div>
        </div>

        <div class="alert alert-info fade-in" th:if="${#lists.isEmpty(categories)}">
            <i class="bi bi-info-circle me-2"></i>
            <span>您还没有创建任何分类</span>
        </div>

        <div class="card fade-in" th:unless="${#lists.isEmpty(categories)}">
            <div class="table-responsive">
                <table class="table table-hover mb-0">
                    <thead>
                        <tr>
                            <th scope="col" style="width: 50px;">#</th>
                            <th scope="col">分类名称</th>
                            <th scope="col">便签数量</th>
                            <th scope="col">创建时间</th>
                            <th scope="col" style="width: 150px;">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr th:each="category, stat : ${categories}">
                            <td th:text="${stat.count}">1</td>
                            <td>
                                <span class="badge" th:style="'background-color: ' + ${category.color} + ';'" th:text="${category.name}">分类名称</span>
                            </td>
                            <td th:text="${category.memoCount}">0</td>
                            <td th:text="${#dates.format(category.createTime, 'yyyy-MM-dd HH:mm')}">创建时间</td>
                            <td>
                                <div class="btn-group btn-group-sm">
                                    <a th:href="@{/category/edit/{id}(id=${category.id})}" class="btn btn-outline-secondary" title="编辑">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <a th:href="@{/category/delete/{id}(id=${category.id})}" class="btn btn-outline-danger" 
                                       onclick="return confirm('确定要删除这个分类吗？该分类下的便签将变为无分类状态。')" title="删除">
                                        <i class="bi bi-trash"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html> 